/**
 * 例子
 * @author luguoxiang
 * @date 2023-03-18
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
import { IConfigSchema } from '@/soar';
import api from './api';

const fieldList: IConfigSchema<any>[] = [
  {
    field: 'value',
    label: '值',
    dataType: 'number',
    table: {
      align: 'center',
      width: 100,
    },
    form: {
      rules({ data, isUpdate }) {
        const { id } = data;
        if (isUpdate && !id) {
          return [];
        }
        return [
          { required: true, message: '必填' },
          // eslint-disable-next-line consistent-return
          api.createValidator((val) => {
            if (val || val === 0) {
              return { $soarQuery: { 'id-ne': id, 'dictId-eq': data.dictId, 'value-eq': val } };
            }
          }),
        ];
      },
    },
  },
  {
    field: 'label',
    label: '名称',
    dataType: 'string',
    form: {
      rules: true,
    },
  },
  {
    field: 'remark',
    label: '备注',
    dataType: 'string',
    form: {
      component: 't-textarea',
    },
  },
  {
    field: 'metadata',
    label: '元数据',
    dataType: 'string',
    form: {
      component: 't-textarea',
    },
  },
  {
    field: 'sort',
    label: '排序',
    dataType: 'number',
    table: {
      align: 'center',
      width: 100,
      order: 1,
    },
  },
  {
    field: 'enumerated',
    label: '是否是枚举值',
    dataType: 'boolean',
    table: false,
    form: false,
  },
  {
    field: 'disabled',
    label: '是否禁用',
    dataType: 'boolean',
    table: {
      width: 100,
    },
  },
];

export default fieldList;
